package com.project.erp.action.system;

import java.util.Locale;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.project.erp.action.BaseAction;
import com.project.erp.common.utils.I18nUtils;

/**
 * 
 * COPYRIGHT (C) 2013 BY XXX公司

 *  功能模块名：国际化

 *  功能描述：更新系统语言action类

 * @author LiJiaGuo    

 * @version 1.0  

 * @created 2013-11-24 下午6:22:15
 */
@Controller
@Scope("prototype")
public class ChangeLanAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2754377618473516291L;
	
	private String language;

	public String changeLan() throws Exception{
		logger.debug("entry changeLan method ...");
		
		try {
			if(!StringUtils.isBlank(language)){
				String[] langRegion;
				Locale locale;
				
				langRegion  = language.split("_");
				locale = new Locale(langRegion[0], langRegion[1]);
				ActionContext.getContext().setLocale(locale);
				I18nUtils.setCurrentLocale(getSession(), locale);//更新session里的国际化值
			}
		} catch (Exception e) {
			logger.error("execute changeLan error!", e);
		}
		
		return SUCCESS;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}
}
